angular.module('increase-account', [])

.controller 'increaseAccountCtrl', ($scope, $localStorage,$state, $http, $ionicHistory, $stateParams, newAddress, wfCache,$ionicViewSwitcher,$ionicPopup,userData,$cordovaSms,showToast) ->
    $scope.countDown = 0
    getCountdown = () ->
        $scope.countDown = 60
        timer = setInterval (->
            $scope.countDown--
            $scope.$apply()
            if $scope.countDown <= 0
                clearInterval timer
        ), 1000
    getCode = () ->
        $http.get("/shopuser/",params:{action:'getmobilecode',shopid:userData.getToken(),userid:$scope.vipItem.id,sendtype:0})
        .success (resp) ->
            if resp.status == '0'
                $scope.msg = resp.msg
                showToast ($scope.msg)
            else
                $scope.msg = resp.msg
                showToast ($scope.msg)
        .error ->
            showToast '请检查网络是否链接'
    _.extend $scope,
        vipItem:$stateParams.vipItem
        confirmInfo:
            inputNumber:undefined
            confirmWord:undefined
        goBack: ->
          $ionicViewSwitcher.nextDirection('back')
          $ionicHistory.goBack()

        getConfirm: ->
            getCountdown()
            getCode()

        confirmReset: ->
            console.log $scope.confirmInfo.inputNumber
            console.log $scope.confirmInfo.confirmWord
            if $scope.confirmInfo.inputNumber != undefined and $scope.confirmInfo.confirmWord != undefined
                $http.post("/shopuser/",{action:'addaccount',shopid:userData.getToken(),userid:$scope.vipItem.id,mobilecode:$scope.confirmInfo.confirmWord,addmoney:$scope.confirmInfo.inputNumber})
                .success (resp) ->
                    if resp.status == '0'
                        showToast '修改成功'
                        $ionicHistory.goBack()
                    else
                        $scope.msg = resp.msg
                        showToast ($scope.msg)
                .error ->
                    showToast '您的网络又调皮了'
            else
                if $scope.confirmInfo.inputNumber == undefined
                    showToast '请输入重置金额'
                else
                    if $scope.confirmInfo.confirmWord == undefined
                        showToast '请输入验证码'




